package com.example.hp.widgettest;

import android.content.Intent;
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import static com.example.hp.widgettest.R.id.textView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView tv;
    private EditText et;
    private Button btngettext, btnsetimg;
    private ImageButton ibn;
    private ImageView iv;
    private RadioGroup rg;
    private RadioButton rbnan,rbnv;
    private CheckBox cblan,cbzu,cbyou;
    private Button btngetgender,btngetfun;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }
    private void init() {
        //获取六个控件
        tv=(TextView)findViewById(R.id.textView2);
        btngettext=(Button)findViewById(R.id.button2);
        btnsetimg=(Button)findViewById(R.id.button3);
        ibn=(ImageButton)findViewById(R.id.imageButton);
        et=(EditText)findViewById(R.id.editText);
       iv=(ImageView)findViewById(R.id.imageView2);
        rg=(RadioGroup)findViewById(R.id.radioGroup);
        rbnan=(RadioButton)findViewById(R.id.radioButton2);
        rbnv=(RadioButton)findViewById(R.id.radioButton);
        cblan=(CheckBox)findViewById(R.id.checkBox);
        cbzu=(CheckBox)findViewById(R.id.checkBox3);
        cbyou=(CheckBox)findViewById(R.id.checkBox2);
        btngetgender=(Button)findViewById(R.id.button4);
        btngetfun=(Button)findViewById(R.id.button5);

        //设置按钮监听器
        btngettext.setOnClickListener(this);
        btnsetimg.setOnClickListener(this);
        ibn.setOnClickListener(this);
        rbnan.setOnClickListener(this);
        rbnv.setOnClickListener(this);
        cbyou.setOnClickListener(this);
        cblan.setOnClickListener(this);
        cbzu.setOnClickListener(this);
        btngetgender.setOnClickListener(this);
        btngetfun.setOnClickListener(this);
    }


    public void onClick(View v) {
        switch (v.getId())
        {
            case R.id.button3://获取并设置文本
                String str=et.getText().toString();
                tv.setText(str);
                break;
            case R.id.button2://设置图片
                iv.setImageResource(R.drawable.three);
                break;
            case R.id.imageButton://图片按钮
                Intent intent=new Intent(MainActivity.this,NewActivity.class);
                intent.putExtra("paraml1",et.getText().toString());
                intent.putExtra("paraml2",3);
                startActivity(intent);
            break;
            case R.id.button4:
                if(rbnan.isChecked())
                    tv.setText("男");
                if(rbnv.isChecked())
                    tv.setText("女");
                break;
            case R.id.button5:
                String msg="";
                if(cblan.isChecked()) msg+="篮球+";
                if(cbzu.isChecked()) msg+="足球+";
                if(cbyou.isChecked()) msg+="游泳+";
                tv.setText(msg);
                break;

        }
    }

}
